//
//  LSNaturalDisasterInfoSearchViewController.m
//  LaSaCivilAffairsDepartment
//
//  Created by 聂志康 on 2018/12/27.
//  Copyright © 2018 wpkj. All rights reserved.
//

#import "LSNaturalDisasterInfoSearchViewController.h"
#import "LSNaturalDisasterInfoTableViewCell.h"
#import "LSInfoSearchTableViewCell.h"

@interface LSNaturalDisasterInfoSearchViewController () <UITextFieldDelegate, UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) UITextField *reportDepartmentTF;
@property (nonatomic, strong) UITextField *searchInfoTF;
@property (nonatomic, strong) UITextField *timeSelectBeginnerTF;
@property (nonatomic, strong) UITextField *timeSelectFinisherTF;
@property (nonatomic, strong) UITableView *naturalDisasterInfoTableView;
@end

static NSString *LSInfoSearchTableViewCellID = @"LSInfoSearchTableViewCellID";

@implementation LSNaturalDisasterInfoSearchViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"自然灾害发生情况查询";
    [self setUpHeaderView];
    [self.view addSubview:self.naturalDisasterInfoTableView];
}

- (void)setUpHeaderView {
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 70)];
    headerView.backgroundColor = UIColor.whiteColor;
    [self.view addSubview:headerView];
    UIView *headerViewBottomLineView = [[UIView alloc] initWithFrame:CGRectMake(0, 69.5, ScreenWidth, 0.5)];
    headerViewBottomLineView.backgroundColor = hexColor(CCCCCC);
    [headerView addSubview:headerViewBottomLineView];
    
    UITextField *reportDepartmentTF = [[UITextField alloc] initWithFrame:CGRectMake((ScreenWidth-310)/2, 8, 110, 24)];
    self.reportDepartmentTF = reportDepartmentTF;
    reportDepartmentTF.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:12];
    reportDepartmentTF.delegate = self;
    reportDepartmentTF.layer.borderColor = hexColor(dbdbdb).CGColor;
    reportDepartmentTF.layer.borderWidth = 0.5;
    reportDepartmentTF.backgroundColor = hexColor(ffffff);
    reportDepartmentTF.text = @"  请选择填报单位";
    UIImageView *reportDepartmentTFRightViewImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
    reportDepartmentTFRightViewImageView.image = [UIImage imageNamed:@"xiala"];
    reportDepartmentTF.rightView = reportDepartmentTFRightViewImageView;
    reportDepartmentTF.rightViewMode = UITextFieldViewModeAlways;
    [headerView addSubview:reportDepartmentTF];
    
    UITextField *searchInfoTF = [[UITextField alloc] initWithFrame:CGRectMake((ScreenWidth-310)/2+120, 8, 310-120, 24)];
    self.searchInfoTF = searchInfoTF;
    searchInfoTF.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:12];
    searchInfoTF.layer.borderColor = hexColor(dbdbdb).CGColor;
    searchInfoTF.layer.borderWidth = 1;
    searchInfoTF.returnKeyType = UIReturnKeySearch;
    searchInfoTF.placeholder = @"请输入您要查找的内容";
    searchInfoTF.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 8, 1)];
    searchInfoTF.leftViewMode = UITextFieldViewModeAlways;
    [headerView addSubview:searchInfoTF];
    UILabel *timeSelectTipLabel = [[UILabel alloc] initWithFrame:CGRectMake((ScreenWidth-310)/2, 30, 38, 40) andText:@"时间:" andTextColor:hexColor(666666) andFont:[UIFont fontWithName:@"SourceHanSansCN-Regular" size:12] andTextAlignment:NSTextAlignmentLeft];
    [headerView addSubview:timeSelectTipLabel];
    UITextField *timeSelectBeginnerTF = [[UITextField alloc] initWithFrame:CGRectMake((ScreenWidth-310)/2+38, 40, 90, 20)];
    self.timeSelectBeginnerTF = timeSelectBeginnerTF;
    timeSelectBeginnerTF.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:11];
    timeSelectBeginnerTF.delegate = self;
    timeSelectBeginnerTF.layer.borderColor = hexColor(dbdbdb).CGColor;
    timeSelectBeginnerTF.layer.borderWidth = 0.5;
    timeSelectBeginnerTF.backgroundColor = hexColor(EEEEEE);
    UIImageView *timeSelectBeginnerTFRightViewImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
    timeSelectBeginnerTFRightViewImageView.image = [UIImage imageNamed:@"xiala"];
    timeSelectBeginnerTF.rightView = timeSelectBeginnerTFRightViewImageView;
    timeSelectBeginnerTF.rightViewMode = UITextFieldViewModeAlways;
    [headerView addSubview:timeSelectBeginnerTF];
    UILabel *zhiLabel = [[UILabel alloc] initWithFrame:CGRectMake((ScreenWidth-310)/2+38+90, 30, 15, 40) andText:@"至" andTextColor:hexColor(666666) andFont:[UIFont fontWithName:@"SourceHanSansCN-Regular" size:12] andTextAlignment:NSTextAlignmentCenter];
    [headerView addSubview:zhiLabel];
    UITextField *timeSelectFinisherTF = [[UITextField alloc] initWithFrame:CGRectMake((ScreenWidth-310)/2+38+90+15, 40, 90, 20)];
    self.timeSelectFinisherTF = timeSelectFinisherTF;
    timeSelectFinisherTF.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:11];
    timeSelectFinisherTF.delegate = self;
    timeSelectFinisherTF.layer.borderColor = hexColor(dbdbdb).CGColor;
    timeSelectFinisherTF.layer.borderWidth = 0.5;
    timeSelectFinisherTF.backgroundColor = hexColor(EEEEEE);
    UIImageView *timeSelectFinisherTFRightViewImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
    timeSelectFinisherTFRightViewImageView.image = [UIImage imageNamed:@"xiala"];
    timeSelectFinisherTF.rightView = timeSelectFinisherTFRightViewImageView;
    timeSelectFinisherTF.rightViewMode = UITextFieldViewModeAlways;
    [headerView addSubview:timeSelectFinisherTF];
    UIButton *searchButton = [[UIButton alloc] initWithFrame:CGRectMake((ScreenWidth-310)/2+38+90+15+90+20, 40, 54, 20)];
    searchButton.backgroundColor = NAV_COLOR;
    [searchButton setTitle:@"搜索" forState:UIControlStateNormal];
    [searchButton setTitleColor:hexColor(f7f7f7) forState:UIControlStateNormal];
    searchButton.layer.cornerRadius = 3;
    searchButton.layer.masksToBounds = true;
    searchButton.titleLabel.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:10];
    [searchButton addTarget:self action:@selector(searchButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [headerView addSubview:searchButton];
}

- (void)searchButtonClick {
    [MBProgressHUD showTipMessageInWindow:@"搜索按钮点击事件"];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 10;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    LSInfoSearchTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:LSInfoSearchTableViewCellID forIndexPath:indexPath];
    cell.mainTitleLabel.text = @"汶川";
    cell.subTitleLabel.text = @"地震";
    cell.bottomLabel.text = @"2019-01-21 11:49:47";
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:true];
}

- (NSArray<UITableViewRowAction*>*)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
//    UITableViewRowAction *rowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"删除" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
//        // 点击删除时 do something
//
//    }];
//    rowAction.backgroundColor = [UIColor redColor];
    UITableViewRowAction *rowaction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"编辑" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
        // 点击置顶时 do something
        
    }];
    rowaction.backgroundColor = NAV_COLOR;
    NSArray *arr = @[rowaction];//rowAction,
    return arr;
}

// 修改编辑按钮文字
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
    return @"编辑";
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return LSInfoSearchTableViewCellHeight;
}

- (UITableView *)naturalDisasterInfoTableView {
    if (!_naturalDisasterInfoTableView) {
        _naturalDisasterInfoTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 70, ScreenWidth, ScreenHeight-SafeAreaTopHeight - 70)];
        _naturalDisasterInfoTableView.backgroundColor = UIColor.whiteColor;
        _naturalDisasterInfoTableView.separatorInset = UIEdgeInsetsZero;
        _naturalDisasterInfoTableView.delegate = self;
        _naturalDisasterInfoTableView.dataSource = self;
        _naturalDisasterInfoTableView.tableFooterView = [UIView new];
        [_naturalDisasterInfoTableView registerClass:LSInfoSearchTableViewCell.class forCellReuseIdentifier:LSInfoSearchTableViewCellID];
    }
    return _naturalDisasterInfoTableView;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
